package com.iflytek.management.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.iflytek.management.pojo.Project;

public interface ProjectMapper {
	//通过id删除项目（假删除）
	@Update("update  Project  set isdelete=1 where proid=#{proid}")
    int deleteByPrimaryKey(Integer proid)throws Exception;
	
	//添加新项目
	@Insert("insert into project (proid, proname, begindate, enddate, customer, remark, belong, isdelete) "
			+ "values (#{proid}, #{proname}, #{begindate}, #{enddate}, #{customer}, #{remark}, #{belong}, 0)")
    int insert(Project record)throws Exception;

//    int insertSelective(Project record);

	//通过id查询项目信息
    @Select("select * from Project where proid=#{proid} and isdelete=0")
    Project selectByPrimaryKey(Integer proid)throws Exception;
    
    //查询全部项目信息
    @Select("select * from Project where isdelete=0")
    @Results({
    	@Result(column = "proid",property = "proid"),
    	@Result(column = "proname",property = "proname"),
    	@Result(column = "begindate",property = "begindate"),
    	@Result(column = "enddate",property = "enddate"),
    	@Result(column = "remark",property = "remark"),
    	@Result(column = "proleader",property = "proleader"),
    	@Result(
    			property = "sysUsersList",
    			column = "proid",
    			many = @Many(select = "com.iflytek.management.mapper.SysUserMapper.findByProid")
    			)
    	
    })
    List<Project>  selectAll()throws Exception;

//    int updateByPrimaryKeySelective(Project record);
    
    //通过id修改项目信息
    @Update("update project set proname = #{proname}, begindate = #{begindate}, enddate = #{enddate}, "
    		+ "remark = #{remark},proleader=#{proleader} where proid = #{proid}")
    int updateProjectByid(Project project)throws Exception;
}